<%@ page import="model.subjects.Enterprise, model.subjects.Person, database.dao.EnterpriseDAO, model.Attribute, java.util.LinkedList, model.Address, java.sql.Date" language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="UTF-8"%>
<jsp:useBean id="enterprise" scope="request" type="model.subjects.Enterprise"/>
<jsp:useBean id="employees" scope="request" type="model.subjects.Employee[]"/>
<jsp:useBean id="roles" scope="request" type="LinkedList<String>"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rollide lisamine ja äravõtmine</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="static/js/javascript.js"></script>

</head>
<body><h1>Rollide lisamine ja äravõtmine</h1>

<a href="#" id="display_contacts" >Kontaktid</a>
<a href="#" id="display_addresses" >Aadressid</a>
<a href="#" id="display_modify_person" >Ettevõtte Andmed</a>

<br>

<div id="show_modify_enterprise">

<h1>Ettevõtte Andmed</h1>

 <form action="s?action=give_role" method="post">
<!--  Üldised atribuudid -->
<input name="enterprise_id" value="<%out.println(enterprise.getId());%>">
Nimi: <%out.println(enterprise.getName());%><br/>
Täisnimi: <%out.println(enterprise.getFullname());%><br/>
<br/>
Vali töötajale roll: <br/>
<select name="role">
<% 
for(String s: roles){
  out.println("<option value=\""+s+"\">"+s+"</option>");
}
%>
</select> 

<div id="remove_role_message" ></div>


<br/><br/>
<table border="1"><tr><td>Eesnimi</td><td>Perenimi</td></tr>
<%
for(int i=0; i<employees.length;i++){
	out.println("<tr>");
	out.println("<td>"+employees[i].getFirst_name()+"</td>");
	out.println("<td>"+employees[i].getLast_name()+ "</td>");
	out.println("<td><input type=\"radio\" name=\"employee_id\" value=\""+employees[i].getId()+"\"></td>");
	out.println("<td><select id='employee_role' name=\"employee_role\">");
	LinkedList<String> employeeRoles = employees[i].getRoles();
	for(String e: employeeRoles){
		out.println("<option value=\""+e+"\">"+e+"</option>");
	}
	out.println("</select></td>");
	//action=\"remove_role("+employees[i].getId()+")\
	//remove_role meetodis oleks vaja ka kätte saada, mis roll kasutajal sellel real selectitud on ja koos töötaja id-ga javasse edasi saata. s?action=remove_role vms
	out.println("<td><button onclick='remove_role("+employees[i].getId()+")'\">Eemalda roll</button></td>");
	out.println("</tr>");
}
%>

<br/>
<br/>
</table>
<input type="submit" value="Lisa valitud roll">
 </form>




</div>
</body>
</html>